<!--正常变更速率变更事件-->
<script>
import Common from "@/mixins/order/commonbg.js";
import OrderService from "@/api/order/OrderService.js";
import PPMForm from "@/crm3.0part7-ppm/core/ppmForm.vue";
export default {
  name: "ipran10461083",
  mixins: [PPMForm, Common],
  data() {
    return {
      //IPRAN	正常变更	速率变更	需求单
      speedOptions: [], //速率列表
      protList: [], //端口类型
      limitSpeed:'',//限制的最大速率
      speedA:'',//A端口
      speedB:'',//B端口
      speedIndex:0,
    };
  },
  async mounted() {
    this.getPorts(); //获取端口号
    let isBatchchange = sessionStorage.getItem('isBatchchange');
    let OldOrderInfo = await this.initCommon();
    this.speedOptions = this.formData["10461544-100000007"].options;
    let ordProdInstsAttrs = OldOrderInfo.ordProdInstsAttrs;
    ordProdInstsAttrs.forEach((item) => {
      if (item.attrCd == "PORT_TYPE") {
        this.protList.push(item.attrValue);
      }
    });
    var protTypeList = ["13144003", "13144004", "13144005"]; //FE,GE,10GE
    if (
      protTypeList.indexOf(this.protList[0]) > -1 &&
      protTypeList.indexOf(this.protList[1]) > -1 && isBatchchange != true
    ) {
      this.formData["10461544-142002453"].isshow = true; //是否速率随选 显示
      this.formData["10461544-142002453"].value = "2"; //默认选否
    } else {
      this.formData["10461544-142002453"].isshow = false; //是否速率随选隐藏
    }
    // this.formData["10461544-142002453"].isshow = true; //是否速率随选 显示
  },

  computed: {},
  methods: {
    getPorts() {
      //获取端口类型
      if (this.protList[0] == "13144003") {
        this.speedA = "FE";
        this.limitSpeed = 100;
      } else if (this.protList[0] == "13144004") {
        this.speedA = "GE";
        this.limitSpeed = 1024;
      } else if (this.protList[0] == "13144005") {
        this.speedA = "10GE";
        this.limitSpeed = 10240;
      }
      if (this.protList[0] == "13144003") {
        this.speedB = "FE";
        this.limitSpeed = 100;
      } else if (this.protList[0] == "13144004") {
        this.speedB = "GE";
        this.limitSpeed = 1024;
      } else if (this.protList[0] == "13144005") {
        this.speedB = "10GE";
        this.limitSpeed = 10240;
      }
    },
    speed(val) {
      this.speedIndex = val
      if (val == "1") {
        if(this.formData["10461544-100000007"].value){
          this.speedVal(val);
        }
      }
    },

    speedVal() {
      let deptName = this.formData["10461544-100000007"].value
        ? this.speedOptions.find(
            (ele) => ele.attrValue === this.formData["10461544-100000007"].value
          ).attrValueName
        : "";
      let limitval = '';
      if(deptName.indexOf('K') != -1){
        limitval = Number(deptName.slice(0,deptName.length-1))/1024
      }else if(deptName.indexOf('M') != -1){
        limitval = Number(deptName.slice(0,deptName.length-1))
      }else if(deptName.indexOf('G') != -1){
        limitval = Number(deptName.slice(0,deptName.length-1))*1024
      }
      if(this.speedIndex == 1){
        if(limitval<2){
          this.$alert("是否“速率随选”选择“是”时，速率下限是2M!", "提示", { type: "warning" });
          this.formData["10461544-100000007"].value = ''
        }else if((this.speedA == "FE" || this.speedA == "FE") && limitval > this.limitSpeed){
          this.$alert("是否“速率随选”选择“是”时，速率上限是100M!", "提示", { type: "warning" });
          this.formData["10461544-100000007"].value = ''
        }else if((this.speedA == "GE" || this.speedA == "GE") && limitval > this.limitSpeed){
          this.$alert("是否“速率随选”选择“是”时，速率上限是1G!", "提示", { type: "warning" });
          this.formData["10461544-100000007"].value = ''
        }else if((this.speedA == "10GE" || this.speedA == "10GE") && limitval > this.limitSpeed){
          this.$alert("是否“速率随选”选择“是”时，速率上限是10G!", "提示", { type: "warning" });
          this.formData["10461544-100000007"].value = ''
        }
      }
    },
  },
};
</script>

